export const animateOnScroll = {
    mounted(el) {
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    el.classList.add('animate-in');
                    observer.unobserve(el);
                }
            });
        }, {
            threshold: 0.1
        });

        observer.observe(el);
    },
    beforeUnmount(el) {
        const observer = new IntersectionObserver(() => {});
        const existingObserver = Array.from(el._observers || []).find(obs => {
            return obs.threshold === 0.1 && obs.callback.toString() === observer.callback.toString();
        });
        existingObserver && existingObserver.unobserve(el);
    }
};

// 实现元素在滚动到接近视口一定比例时触发特定动画效果
